# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=multiscanner
pkgver=1559.86e0145
pkgrel=4
pkgdesc='Modular file scanning/analysis framework.'
groups=('blackarch' 'blackarch-scanner' 'blackarch-automation')
arch=('any')
url='https://github.com/mitre/multiscanner'
license=('Mozilla')
depends=('python2' 'python2-requests' 'python2-magic' 'python2-flask'
         'python2-configparser' 'python2-bitstring' 'python2-paramiko'
         'python2-pefile' 'python2-ssdeep' 'python2-sqlalchemy'
         'python2-sqlalchemy-utils' 'python2-pymongo' 'python2-pyclamd'
         'python2-elasticsearch')
makedepends=('git')
source=("git+https://github.com/mitre/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

build() {
  cd $pkgname

  python2 setup.py build
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"
  install -dm 755 "$pkgdir/usr/share/doc/$pkgname"

  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  cp -a --no-preserve=ownership docs/* "$pkgdir/usr/share/doc/$pkgname/"

  cp -a --no-preserve=ownership multiscanner/* "$pkgdir/usr/share/$pkgname/"

  python2 setup.py install --root="$pkgdir" --prefix=/usr --optimize=1 \
    --skip-build

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python2 ms.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

